package cn.felord.debezium.task;

import cn.felord.debezium.common.Watch;
import cn.felord.debezium.mina.MinaServer;
import cn.felord.debezium.mina.MinaServer9001;
import cn.felord.debezium.service.TcpActService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

@Configuration
@EnableScheduling
@Slf4j
public class WatchTask {
    @Value("${socket.port}")
    private Integer port;
//    @Autowired
//    TcpActService tcpActService;
    @Autowired
    MinaServer minaServer;
    @Autowired
    MinaServer9001 minaServer9001;

    @Scheduled(cron = "0/5 * * * * ?")
    private void myTasks() throws IOException {
        if(!MinaServer.isRun){
            System.out.println("执行定时任务 mina 。。。。" );
            minaServer.start();
        }
        if(!MinaServer9001.isRun){
            System.out.println("执行定时任务 " + port + "启动中 2线读码器启动");
            minaServer9001.start();
        }
    }
}
